// 2025/5/20
// 天使果冻

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, q, x, tmp; 
    cin >> n;
    vector<pair<int, int>> dp(n, {0, 0});
    cin >> dp[0].second;
    for(int i = 1; i < n; i++)
    {
        cin >> tmp;
        if(tmp > dp[i - 1].second)
        {
            dp[i].first = dp[i - 1].second;
            dp[i].second = tmp;
        }
        else if(tmp > dp[i - 1].first)
        {
            dp[i].second = dp[i - 1].second;
            dp[i].first = tmp;
        }
        else 
        {
            dp[i] = dp[i - 1];
        }
    }
    cin >> q;
    while(q--)
    {
        cin >> x;
        cout << dp[x - 1].first << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")